<?php
namespace Home\Controller;
use Think\Controller;
class ConsoleController extends Controller {

    private $baseurl = "http://128.199.209.239/IM/index.php/Home/";


    public function index(){

        $db_directory = M('directory');
        $directories = $db_directory->select();
        $this->assign('directories', $directories);

        $this->assign('baseurl', $this->baseurl);
        $this->display();
    }


    public function menu(){

    	$db_menu = M('menu');
    	$db_link = M('link');

        $directory_id = I('directory_id');

        $menu_list = $db_menu->where("directory_id = '%d'", $directory_id)->order('menu_name_en asc')->select();

        $this->assign('baseurl', $this->baseurl);
        $this->assign('menu_list', $menu_list);
        $this->assign('directory_id', $directory_id);
        $this->display();
    }

    public function link(){

        $db_menu = M('menu');
        $db_link = M('link');

        $menu_id = $_GET['menu_id'];

        $menu_list = $db_menu->where("parent_id = '%d'", $menu_id)->order('menu_name_en asc')->select();
        $link_list = $db_link->where("parent_id = '%d'", $menu_id)->order('link_name_en asc')->select();
            //echo json_encode($link_list);

        $parent['name'] = I('parent_name');
        $parent['id'] = I('parent_id');

        $this->assign('baseurl', $this->baseurl);
        $this->assign('menu_list', $menu_list);
        $this->assign('link_list', $link_list);
        $this->assign('parent', $parent);
        $this->display();
    }


    public function login(){
        $this->assign('baseurl', $this->baseurl);
        $this->display();
    }

    public function news(){
        $db_news = M('news');
        $news_id = I('news_id');
        $news = $db_news->where("news_id='%d'", $news_id)->find();
        $this->assign('baseurl', $this->baseurl);
        $this->assign('news', $news);
        $this->display();
    }

    public function newsList(){
        $db_news = M('news');
        $this->assign('baseurl', $this->baseurl);
        
        $news = $db_news->order('update_time desc')->select();
        $this->assign('news', $news);
        $this->display();
    }


    public function photoEdit(){

        $folder_id = I('folder_id');
        $db_folder = M('folder');
        $db_photo = M('photo');
        $folder = $db_folder->where("folder_id='%d'", $folder_id)->find();
        $cover = $db_photo->where("photo_id='%d'", $folder['cover_id'])->find();

        $this->assign('cover', $cover['photo_name']);
        $this->assign('baseurl', $this->baseurl);
        $this->assign('folder_id', $folder_id);
        //echo $folder_id;
        $this->display();
    }

    public function photo(){
        $folder_id = I('id');
        $this->assign('folder_id', $folder_id);
        $this->display();
    }


    public function photoFolderEdit(){
        $this->assign('baseurl', $this->baseurl);

        $db_folder = M('folder');
        $folders = $db_folder->select();

        $this->assign('folders', $folders);
        $this->display(); 
    }


    public function welcome(){
        $this->assign('baseurl', $this->baseurl);
        $db_welcome = M('welcome');
        $message = $db_welcome->where("id=1")->find();
        $this->assign('welcome', $message);

        $this->display();        
    }

}